"""
本文件用于将使用contrast methods 跑好的结果文件移动到目标路径下
"""

from glob import glob
import os
import shutil


def move_contrast_methods_from_list(src_path, dst_dir, dry_run=False):
    """
    将单个原始文件拷贝到目标目录。
    Args:
        src_path (str): 原文件完整路径
        dst_dir (str):  目标目录
        dry_run (bool): 是否仅打印而不实际移动
    """
    src_path = os.path.abspath(os.path.expanduser(src_path))
    if not os.path.isfile(src_path):
        raise FileNotFoundError("源文件不存在: {}".format(src_path))

    dst_dir = os.path.abspath(os.path.expanduser(dst_dir))
    if not dry_run:
        os.makedirs(dst_dir, exist_ok=True)

    # 目标文件名
    basename = os.path.basename(src_path)
    dst_file = os.path.join(dst_dir, basename)

    if dry_run:
        print("[DRY-RUN] {} -> {}".format(src_path, dst_file))
        return

    shutil.copy(src_path, dst_file)
    print("[MOVED] {} -> {}".format(src_path, dst_file))


if __name__ == "__main__":
    # 移动mcinr
    # 选择哪几个subject
    source_dir = (
        "/media/userdisk5/gqyang/new_frame/datasets/T2map/t2map_test/DJY^DU JIYUAN"
    )
    target_dir = "../prediction/DJY/source"
    source_files = glob(os.path.join(source_dir, "*.nii.gz"))
    for source_file in source_files:
        move_contrast_methods_from_list(source_file, target_dir, dry_run=False)
